<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="shiro"  uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx_path" value="<%=request.getContextPath() %>" />
<script type="text/javascript">
var editorContext=null;
jQuery(function($){
    editorContext = createKindEditor("context");
    $('#input-image-1').ace_file_input({
        no_file:'请选择文章图片 ...',
        no_icon:'fa-file',
        btn_choose:'拖动图片或者点击选择图片',
        btn_change:'重新选择上传图片',
        droppable:true,
        onchange:null,
        thumbnail:false, //| true | large
        before_change:function(files,dropped){//设置允许上传的格式
            var allowed_files = [];
            for(var i = 0 ; i < files.length; i++) {
                var file = files[i];
                if(typeof file === "string") {
                    //IE8 and browsers that don't support File Object
                    if(! (/\.(gif|jpg|jpeg|png|bmp)$/i).test(file) ) return false;
                }
                else {
                    var type = $.trim(file.type);
                    if( !(/\.(gif|jpg|jpeg|png|bmp)$/i).test(file.name ))
                        continue;
                }
                allowed_files.push(file);
            }
            if(allowed_files.length == 0) return false;
            return allowed_files;
        }
    });

	$('#staticEditForm').validate({
		errorElement: 'div',
     	errorClass: 'help-block',
     	focusInvalid: false,
     	rules:{
     		title:{
     			required : true
     		},
     		summary:{
     			required : true
     		}
     	},
     	highlight: function (e) {
    		$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
    	},
    	success: function (e) {
    		$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
    		$(e).remove();
    	},
    	submitHandler: function(form) {
    		  $(form).ajaxSubmit({
    				beforeSubmit: showRequest,
    				success:       showResponse
    		});  
    	},
    	errorPlacement: function(error, element) {
    		if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
    	}
	});
	
	function showRequest(formData, jqForm, options){
	 	var queryString = $.param(formData);
	 	art.dialog({id:'uploadDialog',title:'正在处理...',content:'<img src="../resources/admin/assets/images/loading2.gif">&nbsp;&nbsp;处理中，请稍后...',width:'250px',height:'120px',lock:true,background:'#ccc'});
	 	return true;
	 }
	 function showResponse(data){
	 	art.dialog.list['uploadDialog'].close();
	 	//var data = eval('(' + data + ')');
	 	if(data.success){
            art.dialog({content:data.msg,resize:true,time:2,icon:'succeed',ok:function(){this.close()}});
	 	}else{
	 		$(".error-text").html(data.msg);
			return;
	 	}
	 }
	
	function showErrorAlert (reason, detail) {
		var msg='';
		if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
		else {
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	}

});

</script>
<div class="breadcrumbs">
	<script type="text/javascript">
		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>
	<ul class="breadcrumb">
		<li>
			<i class="ace-icon fa fa-home home-icon"></i>
			<a href="#">首页</a>
		</li>
		<li class="active">编辑新闻</li>
	</ul><!-- /.breadcrumb -->
	
	<div class="nav-search" id="nav-search">
		<form class="form-search">
			<span class="input-icon">
				<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
				<i class="ace-icon fa fa-search nav-search-icon"></i>
			</span>
		</form>
	</div><!-- /.nav-search -->
</div>
<div class="page-content">
	<div class="row">
		<div class="col-xs-12">
			<form class="form-horizontal" role="form" id="staticEditForm" method="post" action="${pageContext.request.contextPath}/cms/static/staticEdit.do">
				<input type="hidden" value="${tStatic.id}" name = "id">
				<div class="form-group">
					<label class="col-sm-1 control-label no-padding-right">文章标题:</label>
					<div class="col-sm-11">
						<input type="text" name="title" class=" col-sm-7" value="${tStatic.title}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label no-padding-right">所属栏目:</label>
					<div class="col-sm-5">
						<select id="form-field-select-1" class="col-xs-10 col-sm-4" name="type">
							<option value='1' <c:if test="${tStatic.type eq 1}">selected</c:if>>关于我们</option>
							<option value="2" <c:if test="${tStatic.type eq 2}">selected</c:if>>联系我们</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label no-padding-right">文章作者:</label>
					<div class="col-sm-11">
						<input type="text" name="author" class=" col-sm-1" value="${tStatic.author}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label no-padding-right">新闻内容:</label>
					<div class="col-sm-11">
                        <textarea id="context" name="context" style="min-height: 500px;">${tStatic.context}</textarea>
					</div>
				</div>
				<div class=" form-group">
					<div class="col-md-offset-1 col-md-9">
						<button class="btn btn-info" type="submit">
							<i class="ace-icon fa fa-check bigger-110"></i>
							保存
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>